package com.chen.blue.controller.admin.system;


import com.chen.blue.annotation.permission.DataPermission;
import com.chen.blue.domain.delete.system.DeptDelete;
import com.chen.blue.domain.delete.system.MenuDelete;
import com.chen.blue.domain.dto.system.*;
import com.chen.blue.domain.dto.system.update.DeptDtoEdit;
import com.chen.blue.domain.dto.system.update.MenuAllDtoEdit;
import com.chen.blue.domain.query.system.DeptQuery;
import com.chen.blue.domain.query.system.MenuQuery;
import com.chen.blue.domain.vo.router.RouterVo;
import com.chen.blue.domain.vo.system.MenuVo;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.DataResult;
import com.chen.blue.result.R;
import com.chen.blue.service.system.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author CLT
 * @since 2024-04-29
 */
@Api(tags = "菜单模块")
@Validated
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private IMenuService iMenuService;

    @ApiOperation(value = "菜单添加", notes = "菜单添加")
    @PostMapping("/add")
    public R add(@RequestBody @Valid MenuAllDto menuAllDto) throws DtoNullException {

        return iMenuService.addMenu(menuAllDto) ? R.success() : R.faild();

    }

    @ApiOperation(value = "菜单删除", notes = "菜单删除")
    @DeleteMapping("/delete")
    public R delete(@RequestBody MenuDelete menuDelete) throws DtoNullException {

        return iMenuService.deleteMenu(menuDelete) ? R.success() : R.faild();

    }

    @ApiOperation(value = "菜单修改", notes = "菜单修改")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid MenuAllDtoEdit menuAllDtoEdit) throws DtoNullException {

        return iMenuService.updateMenuById(menuAllDtoEdit) ? R.success() : R.faild();

    }

    @DataPermission
    @ApiOperation(value = "多条件查询菜单(已配数据权限)", notes = "多条件查询菜单(已配数据权限)")
    @PostMapping("/query")
    public R<DataResult<List<MenuVo>>> query(@RequestBody MenuQuery menuQuery) throws DtoNullException {

        return R.success(iMenuService.queryMenu(menuQuery, false));

    }

    @ApiOperation(value = "ID查询菜单", notes = "ID查询菜单")
    @GetMapping("/queryById/{id}")
    public R<DataResult<List<MenuVo>>> queryById(@PathVariable("id") Long id) throws DtoNullException {

        return R.success(iMenuService.queryMenuById(id));

    }

    @DataPermission
    @ApiOperation(value = "获取路由(已配数据权限)", notes = "获取路由(已配数据权限)")
    @GetMapping("/getRouter")
    public R<DataResult<List<RouterVo>>> queryRouter() throws DtoNullException {

        return R.success(iMenuService.queryRouter());

    }

}

